#include "customerWidget.h"
#include "ui_customerWidget.h"
#include <QMessageBox>

customerWidget::customerWidget(const QString name,const QString pwd,QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::customerWidget)
    , c(name,pwd)
{
    ui->setupUi(this);
}

customerWidget::~customerWidget()
{
    delete ui;
}

void customerWidget::on_queryname_clicked()
{
    ui->result->clear();
    QString name=ui->name->text();
    try{
        QString line=c.queryName(name);
        ui->result->append(line);
    }catch(const QString& ex){
        ui->result->append(ex);
    }
}

void customerWidget::on_querypopular_clicked()
{
    ui->result->clear();
    try{
        QString name=c.queryPopular();
        ui->result->append(name);
    }catch(const QString& ex){
        ui->result->append(ex);
    }
}

void customerWidget::on_queryall_clicked()
{
    ui->result->clear();
    QStringList lines = c.queryAll();

    for (int i = 0; i < lines.size(); i++) {
        QString line = lines[i];
        ui->result->append(line);
    }
}

void customerWidget::on_queryprice_clicked()
{
    ui->result->clear();
    QString minprice = ui->minprice->text();
    QString maxprice = ui->maxprice->text();
    try{
        QStringList lines = c.queryPrice(minprice.toDouble(), maxprice.toDouble());

        for (int i = 0; i < lines.size(); i++) {
            QString line = lines[i];
            ui->result->append(line);
        }
    }catch(const QStringList &e){
        ui->result->append("该价格区间菜单为空！请检查！");
    }
}

void customerWidget::on_order_clicked()
{
    QString name=ui->ordername->text();
    int num=ui->ordernum->text().toInt();
    c.orderFood(name,num);
    QMessageBox::information(this, "提示", "点单成功！");
}

void customerWidget::on_startorder_clicked()
{
    c.startOrder();
    QMessageBox::information(this, "提示", "请开始点单！");
}

void customerWidget::on_checkorder_clicked()
{
    ui->result->clear();
    QMessageBox::information(this, "提示", "查看订单成功！");
    QStringList lines=c.checkOrder();
    for (int i = 0; i < lines.size(); i++) {
        QString line = lines[i];
        ui->result->append(line);
    }
}

void customerWidget::on_submitorder_clicked()
{
    QString man=ui->man->currentText();
    c.submitOrder(man);
    QMessageBox::information(this, "提示", "提交订单成功！");
}

void customerWidget::on_return_2_clicked()
{
    QString num=ui->number->text();
    c.returnOrder(num);
    QMessageBox::information(this, "提示", "退订成功！");
}

void customerWidget::on_orderagain_clicked()
{
    QString man=ui->man->currentText();
    qDebug()<<man;
    c.orderAgain(man);
    QMessageBox::information(this, "提示", "再来一份操作成功！");
}

